package com.bjtu.literatureclient.dao.user;

import com.bjtu.literatureclient.domain.user.UserIndexNoTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserIndexDao {

	void addUserIndexNoTable(UserIndexNoTable userIndexNo);

	int getDistinctIndex(String indexNo);

	int getDistinctIndex1(String indexNo);

	List<UserIndexNoTable> queryAllIndexByUser(String userNo);

	UserIndexNoTable queryByuserAndindex(@Param("userNo") String userNo, @Param("indexNo") String indexNo);

	@Update("<script>update userindexnotable  SET Status=${status} where UserNo=#{userNo} AND IndexNo=#{indexNo}</script>")
    void modifyUserIndexNoTable(@Param("status") int status, @Param("userNo") String userNo, @Param("indexNo") String indexNo);

	void deleteUserIndexNoTable(@Param("userNo") String userNo, @Param("indexNo") String indexNo);

	void addDeletedindexnotable(@Param("indexNo") String indexNo, @Param("stamp") String date);

	@Select("<script>SELECT * FROM userindexnotable WHERE UserNo=#{userNo} and IndexNo!=\"0\" and (IndexCode=\"JC\" or IndexCode=\"JE\")</script>")
    List<UserIndexNoTable> queryAllreference(String userNo);

    void editUserIndexNoTable(UserIndexNoTable userIndexNo);

    @Select("select * from userindexnotable where UserNo=#{userNo} and stamp > #{beginTime}")
    List<UserIndexNoTable> queryByBeginTime(@Param("beginTime") LocalDateTime beginTime, @Param("userNo") String userNo);

	// 使用需要 UserIndexDao.queryUserIndexNoLike(indexPrefix + "%")
	@Select("select IndexNo from userindexnotable where IndexNo Like  #{indexPrefix} ")
	List<String>  queryUserIndexNoLike(@Param("indexPrefix") String indexPrefix);

	@Update("update userindexnotable set IndexNo = #{newIndexNO} where IndexNo = #{newIndexNO}")
	Boolean updateIndexNoByIndexNo(@Param("oldIndexNO")String oldIndexNO, @Param("newIndexNO")String newIndexNO);

}
